Skip to content

Name unreadable spec files and keep validating the rest - #525

Open
Qrytics wants to merge 1 commit into
python-openapi:masterfrom
Qrytics:pilot/slot-650-fix
Open

Qrytics wants to merge 1 commit into
python-openapi:masterfrom
Qrytics:pilot/slot-650-fix

Conversation

@Qrytics

@Qrytics Qrytics commented Nov 10, 2026

Copy link
Copy Markdown

Problem

When validating multiple spec files, a file that cannot be read (missing
path, directory, unreadable file) aborts the whole run in two unhelpful
ways:

  1. The error message names no file: main() prints the bare exception
    (No such file: foo.yaml), so with several inputs you cannot tell
    which one failed.
  2. sys.exit(1) fires immediately, so the files listed after the bad one
    are never validated.

Repro

openapi-spec-validator i_dont_exist.yaml petstore.yaml

Before: prints No such file: i_dont_exist.yaml and exits; petstore.yaml
is never checked.

Fix

In openapi_spec_validator/__main__.py, report read failures through the
existing print_error(filename, exc) helper (so the message carries the
file name), keep validating the remaining files, and exit nonzero at the
end if any input failed to read. Validation-error paths are untouched, and
the single-file case still exits nonzero with the same message text.

Tests

Added test_read_error_names_file_and_continues to
tests/integration/test_main.py: a missing file followed by a valid spec
prints i_dont_exist.yaml: Error: ... AND petstore.yaml: OK, then exits
nonzero. Fails before the fix (valid file never processed), passes after.
Full tests/integration/test_main.py: 23 passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant